package unm

import unm.domain.Catalog
import unm.domain.College
import unm.domain.Page
import unm.domain.PageSub
import unm.excel.CatalogExcel
import unm.excel.CollegeExcel
import unm.domain.CollegeDepart
import unm.excel.PageExcel

class DataLoader {
//    public static void main(String[] args) {
//        def data = getCatalog()
//        data.each {
//            println it
//        }
//    }

    static List<List<Catalog>> getCatalog() {
        def clistlist = []
        def clist = null
        CatalogExcel.load().each {
            if (it.type == 'title') {
                clist = []    // reset clist
                clistlist << clist
            }
            clist << new Catalog(it)
        }
        return clistlist
    }

    static List<College> getCollege() {
        def data = []
        College college = null
        CollegeExcel.load().each {
            if (it.type == 'college') {
                college = new College(it)
                data << college
            } else {
                college.departs << new CollegeDepart(it)
            }
        }
        return data
    }

    static List<Page> getPage() {
        def data = []
        Page page = null
        PageExcel.load().each {
            if (it.type == 'level1') {
                page = new Page(it)
                data << page
            } else {
                page.pageSubs << new PageSub(it)
            }
        }
        return data
    }
}
